/*
 * Copyright (c) 2025 GuoKaiHong (Shenzhen) Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import { initCallback } from "./i_id_card_service";
import { sayHelloCallback } from "./i_id_card_service";
import { selfCheckCallback } from "./i_id_card_service";
import { idc_card_searchCallback } from "./i_id_card_service";
import { idc_card_selectCallback } from "./i_id_card_service";
import { fetch_card_infoCallback } from "./i_id_card_service";
import { gkh_identity_card_closeCallback } from "./i_id_card_service";
import IIdCardService from "./i_id_card_service";
import rpc from "@ohos.rpc";

export default class IdCardServiceStub extends rpc.RemoteObject implements IIdCardService {
  constructor(des: string) {
    super(des);
  }

  onRemoteRequest(code: number, data, reply, option): boolean {
    console.log("onRemoteRequest called, code = " + code);
    switch (code) {
      case IdCardServiceStub.COMMAND_INIT: {
        let _deviceId = data.readInt();
        this.init(_deviceId, (errCode) => {
          reply.writeInt(errCode);
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_SAY_HELLO: {
        let _str = data.readString();
        this.sayHello(_str, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeString(returnValue);
          }
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_SELF_CHECK: {
        this.selfCheck((errCode) => {
          reply.writeInt(errCode);
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_IDC_CARD_SEARCH: {
        this.idc_card_search((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_IDC_CARD_SELECT: {
        this.idc_card_select((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_FETCH_CARD_INFO: {
        this.fetch_card_info((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeString(returnValue);
          }
        });
        return true;
      }
      case IdCardServiceStub.COMMAND_GKH_IDENTITY_CARD_CLOSE: {
        this.gkh_identity_card_close((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      default: {
        console.log("invalid request code" + code);
        break;
      }
    }
    return false;
  }

  init(deviceId: number, callback: initCallback): void {
  }

  sayHello(str: string, callback: sayHelloCallback): void {
  }

  selfCheck(callback: selfCheckCallback): void {
  }

  idc_card_search(callback: idc_card_searchCallback): void {
  }

  idc_card_select(callback: idc_card_selectCallback): void {
  }

  fetch_card_info(callback: fetch_card_infoCallback): void {
  }

  gkh_identity_card_close(callback: gkh_identity_card_closeCallback): void {
  }

  static readonly COMMAND_INIT = 1;
  static readonly COMMAND_SAY_HELLO = 2;
  static readonly COMMAND_SELF_CHECK = 3;
  static readonly COMMAND_IDC_CARD_SEARCH = 4;
  static readonly COMMAND_IDC_CARD_SELECT = 5;
  static readonly COMMAND_FETCH_CARD_INFO = 6;
  static readonly COMMAND_GKH_IDENTITY_CARD_CLOSE = 7;
}

